import 'package:flutter/material.dart';

class _PageNewsItem extends StatelessWidget {
  final String _title;
  final String _time;
  _PageNewsItem(int index, String title, String time)
      : assert(title != null, time != null),
        _title = title,
        _time = time;

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      onTap: () {},
      child: Container(
        padding: const EdgeInsets.all(10.0),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(color: Color(0xffebebeb), width: 1.0),
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          //crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              width: 10.0,
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    _title,
                    style: TextStyle(fontSize: 14.0, color: Color(0xff333333)),
                  ),
                ],
              ),
            ),
            SizedBox(
              width: 10.0,
            ),
            Column(
              children: <Widget>[
                Text(_time,
                    style: TextStyle(fontSize: 10.0, color: Color(0xff999999))),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class Child extends StatefulWidget {
  @override
  _ChildState createState() => _ChildState();
}

class _ChildState extends State<Child> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  List data = [];

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    //getHttp();

    return new Scaffold(
        appBar: new AppBar(
          title: Text('园区动态'),
        ),
        body: Stack(
          fit: StackFit.passthrough,
          children: <Widget>[
            Container(
              height: MediaQuery.of(context).size.height,
              width: MediaQuery.of(context).size.width,
              child: Container(
                alignment: Alignment.topCenter,
                height: 50,
                width: 100,
                child: FlatButton(
                color: Colors.blue,
                padding: EdgeInsets.all(0),
                child: Text(
                  '点击',
                  style: TextStyle(color: Colors.red, fontSize: 20),
                ),
                onPressed: () {
                  print('object');
                  changedata();
                },
              ),
              )
            ),
            Positioned(
              top: 90,
              left: 20,
              right: 20,
              // bottom: 0,
              child: Container(
                height: 200,
                color: Colors.yellow,
              ),
            ),
             Positioned(
              top: 330,
              left: 20,
              right: 20,
              // bottom: 0,
              child: Container(
                height: 200,
                color: Colors.orange,
              ),
            ),
            Positioned(
              top: 50,
              left: 20,
              right: 20,
              child: listbuilder(),
            ),
          ],
        ));
  }

  void changedata() {
    setState(() {
      data = [
        {'title': '1维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '2维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '3维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '4维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '5维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '6维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '7维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '8维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '9维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '10维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '11维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '12维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '13维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '14维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '15维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '16维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '17维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '18维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '19维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
        {'title': '20维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'}
      ];
    });
  }

  Widget listbuilder() {
    return Container(
      height: 300,
      padding: EdgeInsets.only(left: 15, right: 15),
      // color: Colors.yellow,
      child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          index++;
          print('在初始化$index');
          return new _PageNewsItem(
              index - 1, data[index - 1]['title'], data[index - 1]['time']);
        },
        itemCount: data.length,
      ),
    );
  }
}
